A common operation performed on a computer is copying a string of bytes or characters from one address in memory, a "source", to another address in memory, a "target". A string of bytes can have a fixed length or a variable length. Typically, when a string of bytes has a variable length, a termination character such as a null character, typically called a zero-byte character, is used to mark the end of the string of bytes. In that situation, a string of bytes is typically delineated or otherwise defined by the address of the first byte of the string and the termination character.
When a copy operation is implemented on a computer as a single instruction, it typically takes multiple cycles to complete. However, some RISC processors use an instruction sequence to perform this operation, where each instruction is executed in a single cycle.
On a RISC System/6000 processor produced by International Business Machines Corporation (IBM), a string with a pre-specified length or termination character is used to copy a variable-length string of bytes. In that approach, the specified number of bytes up to the termination character are copied, starting at the beginning of the string. A "Load String And Compare Byte Indexed" (lscbx) instruction is used to load consecutive bytes in storage into consecutive registers and then a store string instruction is used to copy those bytes from the registers back into storage. However, this approach typically uses multiple cycles to complete the instruction. This increases hardware and exception-handling complexity, since most other instructions on the processor are designed to be implemented in a single cycle.
The RISC System/6000 lscbx instruction is described in "AIX Version 3.2 for RISC System/6000, Assembler Language Reference", International Business Machines Corporation, Second Edition (January 1992), pg. 5-156 through pg. 5-158. RISC System/6000 is a trademark of International Business Machines Corporation. IBM is a registered trademark of International Business Machines Corporation.
In an approach used in Hewlett Packard Company's Precision Architecture (HP-PA), a UNIT XOR instruction can detect whether a word contains a zero byte. In that approach an exclusive-or operation is performed and hardware detection logic checks each resulting byte for a zero-byte value. A status result can be set to indicate whether any bytes in the resulting word were zero. However, this instruction does not indicate the location of the zero byte. Additional instructions are used to detect the actual location of the zero byte.
Moreover, additional instructions are used to handle leading bytes, i.e. data bytes in front of the starting address of the byte string being copied, by properly performing a logical OR on the word being tested and a disabling mask field. The overhead of generating and using the mask on leading bytes can be significant for copy operations performed on small byte strings.
For background information on Hewlett Packard's Precision Architecture and the UNIT XOR instruction in particular, see "PA-RISC 1.1 Architecture and Instruction Set Reference Manual", Hewlett Packard Company, Chapter 5, pgs. 5-7, 5-109 (1990).
In an approach used in an AM29050 microprocessor by Advanced Micro Devices, Inc. (AMD), a CPBYTE instruction can be used to perform a byte-by-byte comparison between two registers to check for an arbitrary termination condition. One of the two registers contains a portion of the string being checked and the other register contains replicated copies of the termination character. The result of the comparison is an indication whether the termination character was found. As with the PA-RISC 1.1 approach, additional instructions are used to determine the location of the termination character and the start address of the string being copied.
The CPBYTE instruction is described in the "Am29050 Microprocessor, User's Manual", Advanced Micro Devices, Inc., (1991), page 8-38. Am29050 is a trademark of Advanced Micro Devices, Inc. AMD is a registered trademark of Advanced Micro Devices, Inc.